{include file="public/head" /}
<link type="text/css" rel="stylesheet" href="/public/static/admin/css/liandong.css">

<div class="cl pd-5 bg-1 bk-gray mt-20"> 修改商品信息</div>

<article class="page-container">

  <form class="form form-horizontal" id="form-article-add" method="post" action="{:url('goods/update')}"
    enctype="multipart/form-data">

    基本信息：

    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品名称：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.goods_name}" placeholder="" id="" name="goods_name">

        <input type="hidden" value="{$goodsData.goods_id}" name="goods_id">

      </div>

    </div>

    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品短名称：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.goods_short_name}" placeholder="" id=""
          name="goods_short_name">

      </div>

    </div>



    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属分类：</label>



      <div class="formControls col-xs-8 col-sm-2">



        <span class="select-box">



          <select name="cate1" class="select select1" required>

            <option value="">选择分类</option>

            {volist name="categoryData1" id="vo"}

            <option value="{$vo.id}" {if condition='$vo.id eq $cateId1' }selected{/if}>{$vo.cate_name}</option>


            {/volist}



          </select>



        </span>



      </div>
      <div class="formControls col-xs-8 col-sm-2">



        <span class="select-box">



          <select name="cate2" class="select select2" required>

            <option value="{$categoryData2.id}">{$categoryData2.cate_name}</option>


          </select>



        </span>



      </div>
      <div class="formControls col-xs-8 col-sm-2">

        <span class="select-box">



          <select name="goods_cate_id" class="select select3" required>

            <option value="{$categoryData3.id}">{$categoryData3.cate_name}</option>
          </select>



        </span>



      </div>



    </div>




    {include file="public/image" /}








    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">商品描述:</label>

      <div class="formControls col-xs-8 col-sm-6">

        <textarea name="description" class="textarea">{$goodsData.description}</textarea>

      </div>

    </div>

    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">商品关键字：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.keywords}" placeholder="" id="" name="keywords">

      </div>

    </div>

    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">是否是精品：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input value="1" name="isbest" type="radio" {if condition="$goodsData.isbest eq 1" }checked="checked" {/if}> 是

        <input value="0" name="isbest" type="radio" {if condition="$goodsData.isbest eq 0" }checked="checked" {/if}> 否

      </div>

    </div>





    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">是否是热销：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input value="1" name="ishot" type="radio" {if condition="$goodsData.ishot eq 1" }checked="checked" {/if}> 是

        <input value="0" name="ishot" type="radio" {if condition="$goodsData.ishot eq 0" }checked="checked" {/if}> 否

      </div>

    </div>



    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">邮费：</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.post_money}" placeholder="" id="" name="post_money">

      </div>

    </div>

    <div class="row cl">



      <label class="form-label col-xs-4 col-sm-2">规格：</label>



      <div class="formControls col-xs-8 col-sm-6">



        <input value="1" name="single_standard" type="radio" class="single_standard1" {if
          condition='$goodsData.single_standard eq 1' }checked{/if}> 统一规格

        <input value="2" name="single_standard" type="radio" class="single_standard2" {if
          condition='$goodsData.single_standard eq 2' }checked{/if} style="margin-left: 30px;"> 多规格



      </div>


    </div>
    <div class="row cl single_standard1_content" {if condition='$goodsData.single_standard eq 1'} style="display: block;"{else/}style="display: none;"{/if}>

      <label class="form-label col-xs-4 col-sm-2">商品价格:</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.goods_price}" required name="goods_price">

      </div>

    </div>



    <div class="row cl  single_standard1_content" {if condition='$goodsData.single_standard eq 1'} style="display: block;"{else/}style="display: none;"{/if}>

      <label class="form-label col-xs-4 col-sm-2">市场价格:</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.market_price}" required name="market_price">

      </div>

    </div>


    <div class="row cl  single_standard1_content" {if condition='$goodsData.single_standard eq 1'} style="display: block;"{else/}style="display: none;"{/if}>

      <label class="form-label col-xs-4 col-sm-2">库存:</label>

      <div class="formControls col-xs-8 col-sm-6">

        <input type="text" class="input-text" value="{$goodsData.stock}" required name="stock">

      </div>

    </div>


    <div class="row cl single_standard2_content" {if condition='$goodsData.single_standard eq 2'} style="display: block;"{/if}>

      <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属类型：</label>

      <div class="formControls col-xs-8 col-sm-8">

        <span class="select-box">

          <select name="type_id" class="select">

            <option value="">所属类型</option>

            {volist name="types" id="vo1"}

            <option value="{$vo1.id}" {if condition="$goodsData.type_id eq $vo1.id" }selected=selected{/if}>
              {$vo1.type_name}</option>

            {/volist}

          </select>

        </span>

        <div class="formControls" id="attr_container" style="margin-top: 20px;"> </div>
        <!-- 多规格生成表格 -->

        <div id="navtab1" style="width: 100%; border: 1px solid #A3C0E8; display:{if condition='$goodsStandardData'}block{else}none{/if} ">
          <div title="扩展信息" tabid="tabItem3">
            <div id="Div1">
              <div position="center">
                <div style="padding: 5px 8px;" class="div_content">
                  <div class="div_contentlist">
                    {volist name="$standardData" id="vo" key='k'}
                    <ul class="Father_Title">
                      <li>{$vo.name}</li>
                    </ul>
                    <ul class="Father_Item<?php echo ($k-1);?>">
                      {volist name="$vo.standard_value" id="vo1"}
                      <li class="li_width">
                        <label onclick="step.Creat_Table()">
                          <input  type="checkbox" name="standard_value_id[{$vo.id}][]"  value="{$vo1.id}" {php}if(in_array($vo1['id'],$attrArr)){echo 'checked';}{/php}>
                          <span class="standard_value">{$vo1.standard_value}</span>
                        </label>
                      </li>
                      {/volist}
                    </ul><br>
                    {/volist}
                  </div>
                  <div class="div_contentlist2">
                    <ul>
                      <li>
                        <div id="createTable"></div>
                      </li>
                    </ul>

                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>



      </div>

    </div>



    <div class="row cl">

      <label class="form-label col-xs-4 col-sm-2">商品简介：</label>

      <div class="formControls col-xs-8 col-sm-9">

        <script id="editor" type="text/plain" name="content" style="width:100%;height:300px;">{$content|raw}</script>

      </div>

    </div>



    <div class="row cl">

      <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">

        <button class="btn btn-primary radius" type="submit"><i
            class="Hui-iconfont">&#xe632;</i> 提交</button>

      </div>

    </div>

  </form>

</article>

<style type="text/css">
  .standardtable {
    border-collapse: collapse;
  }

  .standardtable input,
  select {
    border: 1px solid #eee;
  }

  .standardtable td {
    border: 1px solid #ddd;
    text-align: center;
    padding: 5px
  }
  .single_standard2_content{
    display: none;
  }
</style>



{include file="public/foot" /}


<script>

  $(function () {

    var ue = UE.getEditor('editor');


    var single_standard=$('input[name="single_standard"]:checked').val();
    if(single_standard==2){
      step.Creat_Table();
    }

    var goods_id=$("input[name='goods_id']").val();
    $.ajax({

      type: "GET",

      url: "ajaxGetAttrPrice/goods_id/"+goods_id ,

      dataType: "json",

      success: function (data) {

        // 循环服务器返回的属性的JSON数据

        $(data).each(function (k, v) {
          $("input[name='goods_price[]']").each(function (k1, v1) {
            if (k1 == k) {
              $(this).val(v.goods_price);
            }
          });
          $("input[name='market_price[]']").each(function (k1, v1) {
            if (k1 == k) {
              $(this).val(v.market_price);
            }
          });
          $("input[name='stock[]']").each(function (k1, v1) {
            if (k1 == k) {
              $(this).val(v.stock);
            }
          });
        });
      }
    });


  });

</script>


<script>

  // 当选择类型时执行AJAX取出类型的属性

  $("select[name=type_id]").change(function () {

    // 获取选中的类型的id

    var type_id = $(this).val();

    if (type_id != "") {

      $.ajax({

        type: "GET",

        url: "/qingadmin/goods/ajaxGetAttr/type_id/" + type_id,

        dataType: "json",

        success: function (data) {

          $("#navtab1").css("display", "inline-block");
          var html = "";

          // 循环服务器返回的属性的JSON数据
          $(data).each(function (k, v) {

              html += "<ul class='Father_Title'><li>" + v.name + "</li></ul><ul class='Father_Item" + k + "'>";

              $(v.standard_value).each(function (k1, v1){

                html+="<li class='li_width'><label onclick='step.Creat_Table()'><input type='checkbox'  value='"+v1.id+"' name='standard_value_id["+v1.standard_id+"][]'/><span class='standard_value'>"+v1.standard_value+"</span></label></li>";

              });


              html += "</ul>";

          });


          $(".div_contentlist").html(html);


        }

      });

    }

    else

      $("#attr_container").html("");

  });



</script>

<script>


var step = {

//SKU信息组合

Creat_Table: function () {

  step.hebingFunction();

  var SKUObj = $(".Father_Title");

  //var skuCount = SKUObj.length;//

  var arrayTile = new Array();//标题组数

  var arrayInfor = new Array();//盛放每组选中的CheckBox值的对象

  var arrayColumn = new Array();//指定列，用来合并哪些列

  var bCheck = true;//是否全选

  var columnIndex = 0;

  $.each(SKUObj, function (i, item) {

    arrayColumn.push(columnIndex);

    columnIndex++;

    arrayTile.push(SKUObj.find("li").eq(i).html().replace("：", ""));

    var itemName = "Father_Item" + i;

    //选中的CHeckBox取值

    var order = new Array();

    $("." + itemName + " input[type=checkbox]:checked").each(function () {

      order.push($(this).parent().children(".standard_value").text());

    });

    arrayInfor.push(order);

    if (order.join() == "") {

      bCheck = false;

    }

    //var skuValue = SKUObj.find("li").eq(index).html();

  });

  //开始创建Table表

  if (bCheck == true) {

    var RowsCount = 0;

    $("#createTable").html("");

    var table = $("<table id=\"process\" border=\"1\" cellpadding=\"1\" cellspacing=\"0\" style=\"width:100%;padding:5px;\"></table>");

    table.appendTo($("#createTable"));

    var thead = $("<thead></thead>");

    thead.appendTo(table);

    var trHead = $("<tr></tr>");

    trHead.appendTo(thead);

    //创建表头

    $.each(arrayTile, function (index, item) {

      var td = $("<th>" + item + "</th>");

      td.appendTo(trHead);

    });

    var itemColumHead = $("<th  style=\"width:70px;\">价格</th> <th  style=\"width:70px;\">市场价格</th><th  style=\"width:70px;\">库存</th>");

    itemColumHead.appendTo(trHead);

    //var itemColumHead2 = $("<td >商家编码</td><td >商品条形码</td>");

    //itemColumHead2.appendTo(trHead);

    var tbody = $("<tbody></tbody>");

    tbody.appendTo(table);

    ////生成组合

    var zuheDate = step.doExchange(arrayInfor);

    if (zuheDate.length > 0) {

      //创建行

      $.each(zuheDate, function (index, item) {

        var td_array = item.split(",");

        var tr = $("<tr></tr>");

        tr.appendTo(tbody);

        $.each(td_array, function (i, values) {

          var td = $("<td>" + values + "</td>");

          td.appendTo(tr);

        });

        var price = $("input[name='goods_price']").val();

        console.log(price);

        var td1 = $("<td ><input name=\"goods_price[]\" class=\"input-text\" type=\"text\" value=\"0\"></td>");

        td1.appendTo(tr);

        var td2 = $("<td ><input name=\"market_price[]\" class=\"input-text\" type=\"text\" value=\"0\"></td>");

         td2.appendTo(tr);

        var td3 = $("<td ><input name=\"stock[]\" class=\"input-text\" type=\"text\" value=\"0\"></td>");

        td3.appendTo(tr);

        //var td4 = $("<td ><input name=\"Txt_SnSon\" class=\"l-text\" type=\"text\" value=\"\"></td>");

        //td4.appendTo(tr);

      });

    }

    //结束创建Table表

    arrayColumn.pop();//删除数组中最后一项

    //合并单元格

    $(table).mergeCell({

      // 目前只有cols这么一个配置项, 用数组表示列的索引,从0开始

      cols: arrayColumn

    });

  } else {

    //未全选中,清除表格

    document.getElementById('createTable').innerHTML = "";

  }

},//合并行

hebingFunction: function () {

  $.fn.mergeCell = function (options) {

    return this.each(function () {

      var cols = options.cols;

      for (var i = cols.length - 1; cols[i] != undefined; i--) {

        // fixbug console调试

        // console.debug(cols[i]);

        mergeCell($(this), cols[i]);

      }

      dispose($(this));

    });

  };

  function mergeCell($table, colIndex) {

    $table.data('col-content', ''); // 存放单元格内容

    $table.data('col-rowspan', 1); // 存放计算的rowspan值 默认为1

    $table.data('col-td', $()); // 存放发现的第一个与前一行比较结果不同td(jQuery封装过的), 默认一个"空"的jquery对象

    $table.data('trNum', $('tbody tr', $table).length); // 要处理表格的总行数, 用于最后一行做特殊处理时进行判断之用

    // 进行"扫面"处理 关键是定位col-td, 和其对应的rowspan

    $('tbody tr', $table).each(function (index) {

      // td:eq中的colIndex即列索引

      var $td = $('td:eq(' + colIndex + ')', this);

      // 取出单元格的当前内容

      var currentContent = $td.html();

      // 第一次时走此分支

      if ($table.data('col-content') == '') {

        $table.data('col-content', currentContent);

        $table.data('col-td', $td);

      } else {

        // 上一行与当前行内容相同

        if ($table.data('col-content') == currentContent) {

          // 上一行与当前行内容相同则col-rowspan累加, 保存新值

          var rowspan = $table.data('col-rowspan') + 1;

          $table.data('col-rowspan', rowspan);

          // 值得注意的是 如果用了$td.remove()就会对其他列的处理造成影响

          $td.hide();

          // 最后一行的情况比较特殊一点

          // 比如最后2行 td中的内容是一样的, 那么到最后一行就应该把此时的col-td里保存的td设置rowspan

          if (++index == $table.data('trNum'))

            $table.data('col-td').attr('rowspan', $table.data('col-rowspan'));

        } else { // 上一行与当前行内容不同

          // col-rowspan默认为1, 如果统计出的col-rowspan没有变化, 不处理

          if ($table.data('col-rowspan') != 1) {

            $table.data('col-td').attr('rowspan', $table.data('col-rowspan'));

          }

          // 保存第一次出现不同内容的td, 和其内容, 重置col-rowspan

          $table.data('col-td', $td);

          $table.data('col-content', $td.html());

          $table.data('col-rowspan', 1);

        }

      }

    });

  }

  // 同样是个private函数 清理内存之用

  function dispose($table) {

    $table.removeData();

  }

},

//组合数组

doExchange: function (doubleArrays) {

  var len = doubleArrays.length;

  if (len >= 2) {

    var arr1 = doubleArrays[0];

    var arr2 = doubleArrays[1];

    var len1 = doubleArrays[0].length;

    var len2 = doubleArrays[1].length;

    var newlen = len1 * len2;

    var temp = new Array(newlen);

    var index = 0;

    for (var i = 0; i < len1; i++) {

      for (var j = 0; j < len2; j++) {

        temp[index] = arr1[i] + "," + arr2[j];

        index++;

      }

    }

    var newArray = new Array(len - 1);

    newArray[0] = temp;

    if (len > 2) {

      var _count = 1;

      for (var i = 2; i < len; i++) {

        newArray[_count] = doubleArrays[i];

        _count++;

      }

    }

    //console.log(newArray);

    return step.doExchange(newArray);

  }

  else {

    return doubleArrays[0];

  }

}

}



</script>



<script type="text/javascript">



  //统一规格 多规格切换
  $(".single_standard1").click(function () {

    $(".single_standard1_content").css("display", "block");
    $(".single_standard2_content").css("display", "none");

  });
  //统一规格 多规格切换
  $(".single_standard2").click(function () {

    $(".single_standard1_content").css("display", "none");
    $(".single_standard2_content").css("display", "block");

  });


  $(".select1").change(function () {
    var html = '<option>选择分类</option>';
    var parent_id = $(".select1").val();
    $.ajax({

      type: "GET",

      url: "/qingadmin/category/ajaxGetCateByP/parent_id/" + parent_id,

      dataType: "json",

      success: function (data) {
        $(data).each(function (k, v) {
          html += "<option value='" + v.id + "'>" + v.cate_name + "</option>";
        });
        $(".select2").html(html);
      }
    });

  });

  $(".select2").change(function () {
    var html = '';
    var parent_id = $(".select2").val();
    $.ajax({

      type: "GET",

      url: "/qingadmin/category/ajaxGetCateByP/parent_id/" + parent_id,

      dataType: "json",

      success: function (data) {
        $(data).each(function (k, v) {
          html += "<option value='" + v.id + "'>" + v.cate_name + "</option>";
        });
        $(".select3").html(html);
      }
    });

  });

</script>

</body>

</html>